/*
 * @Author: your name
 * @Date: 2020-12-10 10:30:26
 * @LastEditTime: 2020-12-18 09:07:02
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \uniapp-ts-uview\src\utils\request.ts
 */

const baseUrl = 'https://bizmp.helloxiaoli.com/'
// const baseUrl = 'http://localhost:8787'
const request = (options: any) => {
    return new Promise((resolve, rejects) => {
        uni.request({
            url: baseUrl + options.url,
            header: {
                ...(uni.getStorageSync('token') ? {Authorization: uni.getStorageSync('token')} : {})
            },
            method: options.methods || 'GET',
            data: options.data,
            dataType: options.dataType || "json",
            success: (res: any) => {
                if(res.code === 1001) {
                    uni.showToast({
                        title:"token失效"
                    })
                }
                resolve(res)
            },
            fail: (e: any) => {
                uni.showToast({
					title:"接口请求失败"
				})
                rejects(e)
            }
        })
    })
}
export default request
